package clases;

import java.awt.Graphics;
import java.awt.Rectangle;

import utils.Constantes;

public abstract class Entidad {

		protected double x;
		protected double y;
		protected Sprite sprite;
		protected double dx = 0;
		protected double dy = 0;
		private Rectangle me = new Rectangle();
		private Rectangle him = new Rectangle();
		private Constantes.orientacion orientacion;
		private int posicionInicialX;
		private int posicionInicialY;
		protected double velocidadMovimiento = 300;
		private Constantes.orientacion orientacionEnChoque;
		
		/**
		 * Construct a entity based on a sprite image and a location.
		 * 
		 * @param ref The reference to the image to be displayed for this entity
	 	 * @param x The initial x location of this entity
		 * @param y The initial y location of this entity
		 */
		public Entidad(String ref,int x,int y) {
			this.sprite = SpriteStore.get().getSprite(ref);
			this.x = x;
			this.y = y;
			this.setPosicionInicialX(x);
			this.setPosicionInicialY(y);
			this.orientacion = Constantes.orientacion.NORTE;
		}
		
		/**
		 * Request that this entity move itself based on a certain ammount
		 * of time passing.
		 * 
		 * @param delta The ammount of time that has passed in milliseconds
		 */
		public void move(long delta) {
			// update the location of the entity based on move speeds
			x += (delta * dx) / 1000;
			y += (delta * dy) / 1000;
		}
		
		/**
		 * Set the horizontal speed of this entity
		 * 
		 * @param dx The horizontal speed of this entity (pixels/sec)
		 */
		public void setMovimientoHorizontal(double dx) {
			this.dx = dx;
		}

		/**
		 * Set the vertical speed of this entity
		 * 
		 * @param dx The vertical speed of this entity (pixels/sec)
		 */
		public void setMovimientoVertical(double dy) {
			this.dy = dy;
		}
		
		/**
		 * Get the horizontal speed of this entity
		 * 
		 * @return The horizontal speed of this entity (pixels/sec)
		 */
		public double getMovimientoHorizontal() {
			return dx;
		}

		/**
		 * Get the vertical speed of this entity
		 * 
		 * @return The vertical speed of this entity (pixels/sec)
		 */
		public double getMovimientoVertical() {
			return dy;
		}
		
		/**
		 * Draw this entity to the graphics context provided
		 * 
		 * @param g The graphics context on which to draw
		 */
		public void dibujar(Graphics g) {
			sprite.draw(g,(int) x,(int) y);
		}
		
		/**
		 * Do the logic associated with this entity. This method
		 * will be called periodically based on game events
		 */
		public void doLogic() {
		}
		
		/**
		 * Get the x location of this entity
		 * 
		 * @return The x location of this entity
		 */
		public int getX() {
			return (int) x;
		}

		/**
		 * Get the y location of this entity
		 * 
		 * @return The y location of this entity
		 */
		public int getY() {
			return (int) y;
		}
		
		/**
		 * Get the x location of this entity
		 * 
		 * @return The x location of this entity
		 */
		public void setX(int x) {
			this.x = x;
		}

		/**
		 * Get the y location of this entity
		 * 
		 * @return The y location of this entity
		 */
		public void setY(int y) {
			this.y=y;
		}
		
		/**
		 * Check if this entity collised with another.
		 * 
		 * @param other The other entity to check collision against
		 * @return True if the entities collide with each other
		 */
		public boolean hacolisionado(Entidad other) {
			me.setBounds((int) x,(int) y,sprite.getWidth(),sprite.getHeight());
			him.setBounds((int) other.x,(int) other.y,other.sprite.getWidth(),other.sprite.getHeight());
			return me.intersects(him);
		}
		
		/**
		 * Notification that this entity collided with another.
		 * 
		 * @param other The entity with which this entity collided.
		 */
		public abstract void colisionacon(Entidad other);

		public Constantes.orientacion getOrientacion() {
			return orientacion;
		}

		public void setOrientacion(Constantes.orientacion orientacion) {
			this.orientacion = orientacion;
		}
		public void setSprite(String ref){
			this.sprite = SpriteStore.get().getSprite(ref);
		}

		public int getPosicionInicialX() {
			return posicionInicialX;
		}

		public void setPosicionInicialX(int posicionInicialX) {
			this.posicionInicialX = posicionInicialX;
		}

		public int getPosicionInicialY() {
			return posicionInicialY;
		}

		public void setPosicionInicialY(int posicionInicialY) {
			this.posicionInicialY = posicionInicialY;
		}

		public Constantes.orientacion getOrientacionEnChoque() {
			return orientacionEnChoque;
		}

		public void setOrientacionEnChoque(Constantes.orientacion orientacionEnChoque) {
			this.orientacionEnChoque = orientacionEnChoque;
		}

		
}
